<template>
	<view>
		<view class="each">
			<view class="name">店铺名称</view>
			<view class="z-flex">
				<input type="text" disabled placeholder="店铺名·24H自助台球(红旗路店)" />
				<image src="../../static/index/hy-right.png" mode=""></image>
			</view>
		</view>

		<view class="each">
			<view class="name">桌台号</view>
			<view class="z-flex">
				<input type="text" placeholder="请输入" />
			</view>
		</view>

		<view class="each">
			<view class="name">手机号</view>
			<view class="z-flex">
				<input type="text" placeholder="请输入您的手机号" />
			</view>
		</view>

		<view class="title">故障内容（必填/可多选）</view>
		<view class="tabs">
			<view class="tab" :class="{'cheTab':cheType.indexOf(index) != -1}" v-for="(item, index) in faultContent" @click="choice(index)">{{ item.name }}</view>
		</view>
		
		<view class="title">描述问题</view>
		<view class="describe">
			<textarea placeholder="请输入您的反馈内容" name="" id="" cols="30" rows="10"></textarea>
		</view>
		
		<view class="title">截图图片</view>
		<view class="upload">
			<u-upload width="77" height="77" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1"
				multiple :maxCount="6">
				<image src="../../static/my/upload.png" mode="widthFix" style="width: 154rpx;height: 154rpx;">
				</image>
			</u-upload>
		</view>

		<view style="height: 160rpx; width: 1rpx"></view>
		<view class="btn-box">
			<view class="PlaceAnOrder-btn" @click="">提交</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			faultContent: [
				{ name: '扫码没反应' },
				{ name: '柜门无法关开启或关闭' },
				{ name: '桌台上的灯不亮' },
				{ name: '物品缺少或损坏（如台球、球杆、粉擦等)' },
				{ name: '球、杆或桌布脏污、破洞、不平整等' }
			],
			cheType: [],
			fileList1: []
		};
	},
	methods: {
		choice(e) {
			if (this.cheType.indexOf(e) == -1) {
				this.cheType.push(e);
			} else {
				this.cheType.splice(this.cheType.indexOf(e), 1);
			}
			console.log(this.cheType)
		},
		
		// 图片处理
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1)
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
		
			let lists = [].concat(event.file)
			// console.log(lists)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
		
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url)
				if (result) {
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.$oss(result),
						ful: result
					}))
					fileListLen++
				} else {
					this[`fileList${event.name}`].splice(fileListLen, 1)
				}
		
			}
		},
		uploadFilePromise(url) {
			let that = this
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: that.$uploadUrl, // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						type: 'image',
						token: uni.getStorageSync('token')
					},
					success: (res) => {
						let data = JSON.parse(res.data)
						if (res.statusCode === 200 && data.code === 1 && data.data) {
							resolve(
								data.data.url
							)
						} else {
							resolve()
						}
					}
				});
			})
		},
	}
};
</script>

<style lang="scss">
.each {
	width: 622rpx;
	padding: 34rpx 32rpx;
	// height: 106rpx;
	background: #f7f8fa;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	margin: auto;
	margin-top: 24rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.name {
		font-weight: bold;
		font-size: 28rpx;
		color: #1c274c;
	}
	input {
		font-size: 28rpx;
		text-align: right;
		width: 440rpx;
	}
	image {
		width: 30rpx;
		height: 30rpx;
	}
}

.each2 {
	width: 622rpx;
	padding: 34rpx 32rpx;
	background: #f7f8fa;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	margin: auto;
	margin-top: 24rpx;
	.name {
		font-weight: bold;
		font-size: 28rpx;
		color: #1c274c;
	}
	.Options-box {
		display: flex;
		align-items: center;
		flex-wrap: wrap;

		.Options {
			margin-right: 42rpx;
			margin-top: 24rpx;
			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 16rpx;
				vertical-align: middle;
			}
			font-weight: 500;
			font-size: 28rpx;
			color: #a4a9b7;
		}
	}
}

.title {
	font-weight: bold;
	font-size: 30rpx;
	color: #1c274c;
	padding: 40rpx 0 0 32rpx;
}
.tabs {
	padding: 0 32rpx;
	.tab {
		display: inline-block;
		margin-top: 24rpx;
		padding: 0 32rpx;
		height: 72rpx;
		line-height: 72rpx;
		border-radius: 41rpx 41rpx 41rpx 41rpx;
		border: 1rpx solid #edeef1;
		font-weight: 500;
		font-size: 28rpx;
		color: #6b738b;
		margin-right: 24rpx;
	}
	.cheTab {
		border: 1rpx solid #4BC264;
	}
}
.describe {
	width: 622rpx;
	height: 132rpx;
	background: #F7F8FA;
	border-radius: 20rpx 20rpx 20rpx 20rpx;
	margin: auto;
	padding: 32rpx;
	margin-top: 24rpx;
	textarea {
		height: 132rpx;
	}
}

.upload {
	margin: 32rpx 30rpx 0 30rpx;
	// margin-top: 32rpx;
}

.btn-box {
	width: 100%;
	position: fixed;
	bottom: 40rpx;
	z-index: 9;
	.PlaceAnOrder-btn {
		width: 686rpx;
		height: 106rpx;
		margin: auto;
		background: #4bc264;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		font-weight: 800;
		font-size: 34rpx;
		color: #ffffff;
		line-height: 106rpx;
		text-align: center;
	}
}
</style>
